package com.yhh.college_information_platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yhh.college_information_platform.entity.Resource;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 资料Mapper接口
 *
 * @author yhh
 * @date 2025-10-25
 */
@Mapper
public interface ResourceMapper extends BaseMapper<Resource> {
    
    /**
     * 增加评论数
     */
    @Update("UPDATE t_resource SET comment_count = comment_count + 1 WHERE id = #{resourceId}")
    int incrementCommentCount(@Param("resourceId") Long resourceId);
    
    /**
     * 减少评论数
     */
    @Update("UPDATE t_resource SET comment_count = comment_count - 1 WHERE id = #{resourceId} AND comment_count > 0")
    int decrementCommentCount(@Param("resourceId") Long resourceId);
}

